package main

import (
	"WebLearning/web-18/pb"
	"context"
	"fmt"
	"google.golang.org/grpc"
	"log"
	"time"
)

//连接服务器
func main() {
	conn, err := grpc.Dial(":8080", grpc.WithInsecure())
	if err != nil {
		fmt.Printf("faild to connect: %v", err)
	}
	defer conn.Close()
	c := pb.NewGreeterClient(conn)
	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	defer cancel()
	// c客户端 调用服务端的SayHello
	response, err := c.SayHello(ctx, &pb.HelloRequest{Name: "my name is ybl"})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}
	log.Printf("greeting :%s", response.GetName())
}
